﻿/**
 过滤外链
 同时，修复百科链接
*/
(function(E, $){

var Consts = E.consts,
	hostname = location.hostname.replace(/\./g, '\\.'),
	reHdwiki = new RegExp("^http:\\/\\/"+hostname, 'i'),
	isFilterExternal = (typeof g_filterExternal === "undefined") ? 0 : g_filterExternal;

E.addFilter('hdwiki', {
	replace: function( dom ){
		if(typeof dom !='object' || !dom.body){return dom;}
		var links = E.$('a');
		links.each(function(){
			var link = $(this),
				href = link.attr('href'),
				text = link.text();
			
			if ( link.is('.innerlink,.baikelink') || /innerlink/i.test( href ) ){
			// 修复百科链接
				link.attr( 'href', 'index.php?doc-innerlink-' + encodeURI(text) );
			}else if( isFilterExternal && href ){
			// 过滤外链
				href = href.toLowerCase();
				if( href.indexOf('http:') === 0 && !reHdwiki.test(href) ) {
					link.replaceWith(link.html());
				}
			}
		});
	}
});

})(jQEditor, jQuery);